//
//  ViewController.swift
//  瀑布流布局
//
//  Created by 崔博 on 2017/5/8.
//  Copyright © 2017年 崔博. All rights reserved.
//

import UIKit


class ViewController: UIViewController {

     fileprivate lazy var collectionView: UICollectionView = {
        let layout = BB_WaterfallLayout()
        layout.sectionInset =  UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
        layout.minimumLineSpacing = 10
        layout.minimumInteritemSpacing = 20
        layout.dataSource = self
        let colllectionView = UICollectionView(frame: self.view.bounds, collectionViewLayout: layout)
        colllectionView.dataSource = self
        
        return colllectionView
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
        
        view.addSubview(collectionView)
        collectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "cell")
    }
}


extension ViewController: UICollectionViewDataSource{
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 100
    }
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
        cell.backgroundColor = UIColor.red
        return cell
    }
}

extension ViewController: BB_WaterfallLayoutDataSource{
    func numberofCols(_ waterfallLayout: BB_WaterfallLayout) -> Int {
        return 3
    }
    func waterFall(_ waterfall: BB_WaterfallLayout, item: Int) -> CGFloat {
        return CGFloat(arc4random_uniform(150) + 100)
    }
}
